<?php
require('fpdf/fpdf.php');
include 'conexao.php';

$alunos = $conn->query("SELECT nome, curso, genero, idade FROM novos_alunos ORDER BY nome ASC")->fetch_all(MYSQLI_ASSOC);

class PDF extends FPDF {
    function Header() {
        $this->SetFont('Arial','B',14);
        $this->Cell(0,10,utf8_decode('Lista Nominal dos Candidatos Inscritos'),0,1,'C');
        $this->Ln(5);
        $this->SetFont('Arial','B',10);
        $this->Cell(10,8,'Nº',1,0,'C');
        $this->Cell(65,8,'Nome',1,0,'C');
        $this->Cell(25,8,'Idade',1,0,'C');
        $this->Cell(35,8,'Género',1,0,'C');
        $this->Cell(50,8,'Curso',1,1,'C');
    }
}

$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',10);

$n = 1;
foreach ($alunos as $a) {
    $pdf->Cell(10,8,$n++,1,0,'C');
    $pdf->Cell(65,8,utf8_decode($a['nome']),1);
    $pdf->Cell(25,8,$a['idade'],1,0,'C');
    $pdf->Cell(35,8,utf8_decode($a['genero']),1,0,'C');
    $pdf->Cell(50,8,utf8_decode($a['curso']),1,1,'C');
}

$pdf->Output();
?>
